package edu.base.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.base.dao.MaintenanceRecordMapper;
import edu.base.model.MaintenanceRecord;
import edu.base.model.MaintenanceRecordJoinUsers;
import edu.base.model.Statistics;

@Service
public class MaintenanceRecordService {

	
	@Autowired
	MaintenanceRecordMapper maintenanceRecordMapper;
	
	
	public Integer insert(MaintenanceRecord item) {
		return maintenanceRecordMapper.insertSelective(item);
	}
	
	public void del(Integer id) {
		maintenanceRecordMapper.deleteByPrimaryKey(id);
	}
	
	public void update(MaintenanceRecord item) {
		maintenanceRecordMapper.updateByPrimaryKeySelective(item);
	}
	
	public MaintenanceRecord findByKey(Integer key) {
		return maintenanceRecordMapper.selectByPrimaryKey(key);
	}
	
	
	public List<MaintenanceRecordJoinUsers> query(Date date1, Date date2, Integer customerId,Integer workerId,Integer state, Integer p,Integer size){
		if(p == null) {
			p = 1;
		}
		return maintenanceRecordMapper.query(date1, date2, customerId, workerId, state, (p-1)*size, size);
	}
	
	public Integer count(Date date1, Date date2, Integer customerId,Integer workerId,Integer state){
		return maintenanceRecordMapper.count(date1, date2, customerId, workerId, state);
	}
	
	public List<Statistics> stat(Integer year) {
		return maintenanceRecordMapper.stat(year);
	}
	
	public List<Statistics> statByDeviceType(Integer year){
		return maintenanceRecordMapper.statByDeviceType(year);
	}
}
